home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / s342q12.lha / nodeedit.c < prev    next >
C/C++ Source or Header  |  1993-12-05  |  22KB  |  974 lines

  1. #include "ctdl.h"
  2.  
  3. #define R_BTM        12
  4. #define R_TOP        8
  5. #define R_RGT        64
  6. #define R_LEFT        16
  7.  
  8. #define SetColors(x, y)        textattr((y << 4) + x)
  9.  
  10. #define ROUTE_WARNING   "WARNING: Outgoing route mail will be lost!"
  11. #define ROUTE_CONFIRM   "Confirm killing %s? "
  12. #define CARRYING_ROUTED "Node is carrying routed mail, cannot reroute."
  13.  
  14. extern CONFIG    cfg;
  15. extern NetBuffer netBuf, netTemp;
  16. extern FILE      *netfl;
  17. extern int       thisNet;
  18. extern NetTable  *netTab;
  19. extern aRoom     roomBuf;        /* room buffer            */
  20. extern FILE      *roomfl;        /* file descriptor for rooms    */
  21. extern int       thisRoom;        /* room currently in roomBuf    */
  22. extern rTable     *roomTab;        /* RAM index of rooms        */
  23. extern VirtualRoom *VRoomTab;
  24. extern VirtNet     *VirtNetList;
  25. extern char VirtualInUse;
  26.  
  27.  
  28. void Error(char *str);
  29. int  DoMN(void);
  30. int  DoRoomSharing(void);
  31. void SetUpMN(char *str);
  32. void EatMN(void);
  33. char Confirm(char *str);
  34. int ValNewSystem(void);
  35. void RunEdit(char clear);
  36. char ShowIt(char *title, char *str, char *accept);
  37. char KillNode();
  38. char DirectRoute(NetBuffer *n);
  39. void DispNetName();
  40. void DispRoomName();
  41. int  CmpNodes();
  42.  
  43. typedef int DataElement;
  44.  
  45. DataElement *AccessElement;
  46. #define KeyStroke (0)
  47. /*int  Keys[] = { INS, 0 }; */
  48. DisplayList NetList = { { NULL, NULL, CmpNodes, free, NULL },
  49.             " Node Selection ",
  50.             NULL, KillNode,
  51.             1, 80, 1, 25,
  52.             0, 0, 0, 0,
  53.             NAMESIZE + 4, DispNetName, NULL, KeyStroke };
  54.  
  55. typedef struct {
  56.     label name;
  57.     label id;
  58.     int num;
  59.     char cond[4];
  60. } NetRec;
  61.  
  62. #define NORMAL_ROOM    0
  63. #define VIRTUAL_ROOM    1
  64. typedef struct {
  65.     label name;
  66.     char mode;
  67.     union {
  68.         SharedRoom ShareInfo;
  69.         VirtPoint  VirtRoom;
  70.     } Room;
  71. } OneSharedRoom;
  72.  
  73. void RoomInfo(OneSharedRoom *data);
  74. void freeNList(SListBase *t);
  75. char ChName(char *str);
  76. char ChId(char *str);
  77. char ChShort(char *str);
  78. char ChRoute(char *str);
  79. char ChBaud(int i);
  80. char WeSpine(char *c);
  81. char IsSpine(char *c);
  82. void NetDisp(), NodeInfo();
  83.  
  84.  
  85. SListBase c1 = { NULL, NULL, NULL, free, NULL };
  86. SListBase c2 = { NULL, NULL, NULL, free, NULL };
  87.  
  88. char *Rates[] = {
  89.     "300", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "57600" ""
  90. };
  91.  
  92. char is_spine, spine;
  93. DataElement *SpEl, *IsEl;
  94.  
  95. #define MN_LEFT        20
  96. #define MN_RIGHT    60
  97. #define MN_TOP        5
  98. #define MN_BOTTOM       24
  99.  
  100. DataElement *AccessElements;
  101.  
  102. Screen MNets = { " M e m b e r   N e t s ", NULL,
  103.         { NULL, NULL, NULL, freeNList, NULL },
  104.           MN_LEFT, MN_TOP, MN_RIGHT, MN_BOTTOM,
  105.           WHITE, BLACK, BLACK, LIGHTGRAY,
  106.          0, 0, 0, 0,
  107.          KeyStroke,
  108.          FULL_BORDER
  109. };
  110.  
  111. char mn[32], MNval[20];
  112.  
  113. SListBase cc1 = { NULL, NULL, NULL, NoFree, NULL };
  114. SListBase cc2 = { NULL, NULL, NULL, NoFree, NULL };
  115.  
  116. char extdialer, oldext;
  117.  
  118. label Router;
  119. DataElement *Baud;
  120.  
  121. char ExtWarn();
  122.  
  123. void RunEdit(clear)
  124. char clear;
  125. {
  126.     char on, s_files, r_files, local, stadel, n_mail, RT, RF, routelock;
  127.  
  128.         getNet(netBuf.nbRoute, &netTemp);
  129.         if (netBuf.nbRouteGen == netTemp.nbGen)
  130.             strCpy(Router, netTemp.netName);
  131.         else {
  132.             strCpy(Router, "<no route>");
  133.             netBuf.nbRoute = -1;
  134.         }
  135.     }
  136.     else strCpy(Router, "<no route>");
  137.  
  138.     on = netBuf.nbflags.OtherNet;
  139.     spine = netBuf.nbflags.spine;
  140.     is_spine = netBuf.nbflags.is_spine;
  141.     s_files = netBuf.nbflags.send_files;
  142.     r_files = netBuf.nbflags.room_files;
  143.     local = netBuf.nbflags.local;
  144.     stadel = netBuf.nbflags.Stadel;
  145.     routelock = netBuf.nbflags.RouteLock;
  146.     n_mail = netBuf.nbflags.normal_mail;
  147.     RT = netBuf.nbflags.RouteTo;
  148.     RF = netBuf.nbflags.RouteFor;
  149.     extdialer = oldext = netBuf.nbflags.ExternalDialer;
  150.  
  151.     SetUpMN(MNval);
  152.  
  153.     AddData(&c1, MakeString("Name", 1, 3, netBuf.netName, NAMESIZE, ChName,
  154.                         TYPICAL, 0), NULL, FALSE);
  155.     AddData(&c2, MakeString("ID", 40, 3, netBuf.netId, NAMESIZE, ChId,
  156.                         TYPICAL, 0), NULL, FALSE);
  157.     AddData(&c2, MakeString("Condensed", 50, 5, netBuf.nbShort, 3,
  158.                        ChShort, TYPICAL, 0), NULL, FALSE);
  159.     AddData(&c1, (AccessElement = MakeString("Access", 1, 5, netBuf.access,
  160.                 40, NULL, TYPICAL, 0)), NULL, FALSE);
  161.     AddData(&c1, MakeString("Our pwd", 1, 7, netBuf.OurPwd, NAMESIZE,
  162.                        NULL, TYPICAL, 0), NULL, FALSE);
  163.     AddData(&c2, MakeString("Their pwd", 40, 7, netBuf.TheirPwd, NAMESIZE,
  164.                        NULL, TYPICAL, 0), NULL, FALSE);
  165.     AddData(&c1, MakeBool("Local System", 1, 9, &local, NULL, TYPICAL, 0),
  166.                                 NULL, FALSE);
  167.     AddData(&c2, MakeBool("OtherNet System", 40, 9, &on, NULL, TYPICAL, 0),
  168.                                 NULL, FALSE);
  169.     AddData(&c1, (SpEl = MakeBool("We are spine", 1, 11, &spine, WeSpine,
  170.                         TYPICAL, 0)), NULL, FALSE);
  171.     AddData(&c2, (IsEl = MakeBool("System is spine", 40, 11, &is_spine,
  172.                        IsSpine, TYPICAL, 0)), NULL, FALSE);
  173.     AddData(&c1, MakeBool("Route mail to", 1, 13, &RT, NULL, TYPICAL, 0),
  174.                                 NULL, FALSE);
  175.     AddData(&c2, MakeBool("Route mail from", 40, 13, &RF, NULL, TYPICAL, 0),
  176.                                 NULL, FALSE);
  177.  
  178.     AddData(&c1, (Baud = MakeLim("Baud rate", 1, 15, Rates,
  179.             netBuf.baudCode, 5, TYPICAL, 0)), NULL, FALSE);
  180.  
  181.     AddData(&c2, MakeUS("Member nets", 40, 15, MNval, DoMN, TYPICAL, 0),
  182.                         NULL, FALSE);
  183.  
  184.     AddData(&c1, MakeString("Routing node", 1, 17, Router, NAMESIZE,
  185.                        ChRoute, TYPICAL, 0), NULL, FALSE);
  186.     AddData(&c2, MakeBool("STadel", 40, 17, &stadel, NULL, TYPICAL,
  187.                             0), NULL, FALSE);
  188.     AddData(&c1, MakeBool("Route Lock", 1, 19, &routelock, NULL, TYPICAL,
  189.                             0), NULL, FALSE);
  190.     AddData(&c2, MakeBool("External Dialer", 40, 19, &extdialer, ExtWarn,
  191.                         TYPICAL, 0), NULL, FALSE);
  192.     AddData(&c1, MakeUS("Room Sharing", 1, 21, " Hit space ", DoRoomSharing,
  193.                         TYPICAL, 0), NULL, FALSE);
  194.  
  195.     AddData(&Node.DataList, &c1, NULL, FALSE);
  196.     AddData(&Node.DataList, &c2, NULL, FALSE);
  197.  
  198.     ScreenIt(&Node, clear);
  199.  
  200.     netBuf.nbflags.OtherNet = on;
  201.     netBuf.nbflags.spine = spine;
  202.     netBuf.nbflags.is_spine = is_spine;
  203.     netBuf.nbflags.send_files = s_files;
  204.     netBuf.nbflags.room_files = r_files;
  205.     netBuf.nbflags.local = local;
  206.     netBuf.nbflags.Stadel = stadel;
  207.     netBuf.nbflags.RouteLock = routelock;
  208.     /* netBuf.nbflags.normal_mail = n_mail; */
  209.     netBuf.baudCode = Baud->val.A_Lim.index;
  210.     netBuf.nbflags.RouteTo = RT;
  211.     netBuf.nbflags.RouteFor = RF;
  212.     netBuf.nbflags.ExternalDialer = extdialer;
  213.     EatMN();
  214.  
  215.     KillList(&Node.DataList);
  216.     KillList(&MNets.DataList);
  217. }
  218.  
  219. void freeNList(SListBase *t)
  220. {
  221.     KillList(t);
  222. }
  223.  
  224. int CmpNodes(s1, s2)
  225. NetRec *s1, *s2;
  226. {
  227.     return strCmpU(s1->name, s2->name);
  228. }
  229.  
  230. void SetUpMN(str)
  231. char *str;
  232. {
  233.     int i;
  234.     char *t, Disabled = TRUE;
  235.     long m = 1l;
  236.  
  237.     MNets.bg = cfg.DepData.ScreenColors.ScrBack;
  238.     MNets.fg = cfg.DepData.ScreenColors.ScrFore;
  239.     MNets.dbg = cfg.DepData.ScreenColors.StatBack;
  240.     MNets.dfg = cfg.DepData.ScreenColors.StatFore;
  241.     MNets.tfg = cfg.DepData.ScreenColors.StatFore;
  242.     MNets.tbg = cfg.DepData.ScreenColors.StatBack;
  243.     MNets.fcf = cfg.DepData.ScreenColors.ScrFore;
  244.     MNets.fcb = cfg.DepData.ScreenColors.ScrBack;
  245.  
  246.     for (i = 0; i < 32; i++, m <<= 1) {
  247.         mn[i] = !((netBuf.MemberNets & m) == 0);
  248.         if (mn[i]) Disabled = FALSE;
  249.     }
  250.  
  251.     strcpy(str, (Disabled) ? " Disabled " : " Active ");
  252.  
  253.     for (i = 0; i < 16; i++) {
  254.         t = GetDynamic(10);
  255.         sprintf(t, "%2d", i+1);
  256.         AddData(&cc1, MakeBool(t, 13, i+3, mn+i, NULL, VALUE_AFTER, 0),
  257.                                 NULL, FALSE);
  258.     }
  259.  
  260.     for (i = 16; i < 32; i++) {
  261.         t = GetDynamic(10);
  262.         sprintf(t, "%2d", i+1);
  263.         AddData(&cc2, MakeBool(t, 19, i+3-16, mn+i, NULL, 0, 0), NULL,
  264.                                 FALSE);
  265.     }
  266.     AddData(&MNets.DataList, &cc1, NULL, FALSE);
  267.     AddData(&MNets.DataList, &cc2, NULL, FALSE);
  268. }
  269.  
  270. void EatMN()
  271. {
  272.     MULTI_NET_DATA m;
  273.     int i;
  274.  
  275.     for (netBuf.MemberNets = 0l, m = 1l, i = 0; i < 32; i++, m <<= 1)
  276.         if (mn[i]) netBuf.MemberNets |= m;
  277. }
  278.  
  279. static char FoundDup, *check;
  280. static NetRec *temp;
  281.  
  282. void CheckName();
  283. void CheckId();
  284.  
  285. char ChName(char *str)
  286. {
  287.     char buf[NAMESIZE * 2];
  288.  
  289.     while (*str == ' ') str++;
  290.     if (strLen(str) == 0)
  291.         return FALSE;
  292.  
  293.     FoundDup = FALSE;
  294.     check = str;
  295.     RunList(&NetList.Data, CheckName);
  296.     if (FoundDup) {
  297.         sprintf(buf, "%s already in use.", str);
  298.         Error(buf);
  299.         return FALSE;
  300.     }
  301.     return TRUE;
  302. }
  303.  
  304. void CheckName(d)
  305. NetRec *d;
  306. {
  307.     if (d->num != thisNet) {
  308.         if (strCmpU(d->name, check) == SAMESTRING) {
  309.             FoundDup = TRUE;
  310.             temp = d;
  311.         }
  312.  
  313.         if (strCmpU(d->cond, check) == SAMESTRING) {
  314.             FoundDup = TRUE;
  315.             temp = d;
  316.         }
  317.     }
  318. }
  319.  
  320. char ChId(char *str)
  321. {
  322.     char buf[80];
  323.     label b;
  324.  
  325.     while (*str == ' ') str++;
  326.     if (strLen(str) == 0)
  327.         return FALSE;
  328.  
  329.     normId(str, b);
  330.     FoundDup = FALSE;
  331.     check = b;
  332.     RunList(&NetList.Data, CheckId);
  333.     if (FoundDup) {
  334.         sprintf(buf, "%s already in use.", str);
  335.         sprintf(buf, "%s already in use (%s).", str,
  336.                             temp->name);
  337.         Error(buf);
  338.         return FALSE;
  339.     }
  340.     ReDoAuxFiles(b);
  341.     return TRUE;
  342. }
  343.  
  344. void CheckId(d)
  345. NetRec *d;
  346. {
  347.     if (d->num != thisNet)
  348.         if (strCmpU(d->id, check) == SAMESTRING) {
  349.             temp = d;
  350.             FoundDup = TRUE;
  351.         }
  352. }
  353.  
  354. char IsSpine(char *c)
  355. {
  356.     if (spine) {
  357.         spine = FALSE;
  358.         SuddenUpdate(&Node, SpEl);
  359.     }
  360.  
  361.     return TRUE;
  362. }
  363.  
  364. char WeSpine(char *c)
  365. {
  366.     if (is_spine) {
  367.         is_spine = FALSE;
  368.         SuddenUpdate(&Node, IsEl);
  369.     }
  370.  
  371.     return TRUE;
  372. }
  373.  
  374. char ChRoute(char *name)
  375. {
  376.     char *s, buf[80], first[50];
  377.  
  378.     s = name;
  379.     while (*name == ' ') name++;
  380.     if (strLen(name) == 0) {
  381.         strcpy(s, "<no route>");
  382.         BackToDirect(thisNet, &netBuf);
  383.         netBuf.nbRoute = -1;
  384.         return TRUE;
  385.     }
  386.     else {
  387.         FoundDup = FALSE;
  388.         check = name;
  389.         RunList(&NetList.Data, CheckName);
  390.         if (!FoundDup) {
  391.             sprintf(buf, "%s not found.", name);
  392.             Error(buf);
  393.             return FALSE;
  394.         }
  395.         getNet(temp->num, &netTemp);
  396.         if (!DirectRoute(&netTemp)) {
  397.             sprintf(buf, "we do not directly connect with %s",
  398.                                 name);
  399.             Error(buf);
  400.             return FALSE;
  401.         }
  402.  
  403.         if (!ReDoRouted(temp->num)) {
  404.             sprintf(buf, CARRYING_ROUTED);
  405.             Error(buf);
  406.             return FALSE;
  407.         }
  408.  
  409.         RouteLocalMail(temp->num);
  410.         netBuf.nbRoute = temp->num;
  411.         netBuf.nbRouteGen = netTemp.nbGen;
  412.         sprintf(buf, "r%d.0", temp->num);
  413.         makeSysName(first, buf, &cfg.netArea);
  414.         netTemp.nbflags.HasRouted = (access(first, 0) == 0);
  415.         putNet(temp->num, &netTemp);
  416.     }
  417.     return TRUE;
  418. }
  419.  
  420. char ChShort(char *str)
  421. {
  422.     int i;
  423.     char buf[80];
  424.  
  425.     for (i = 0; i < cfg.netSize; i++) {
  426.         if (i != thisNet &&
  427.                  strCmpU(str, netTab[i].ntShort) == SAMESTRING) {
  428.             getNet(i, &netTemp);
  429.             if (netTemp.nbflags.in_use) {
  430.                 sprintf(buf, "%s already in use (%s).", str,
  431.                             netTemp.netName);
  432.                 Error(buf);
  433.                 return FALSE;
  434.             }
  435.         }
  436.     }
  437.  
  438.     return TRUE;
  439. }
  440.  
  441. #define realen(s)    (strlen(s) + 8)
  442. char ShowIt(title, str, accept)
  443. char *str, *title, *accept;
  444. {
  445.     void *Save;
  446.     int left, right, c;
  447.  
  448.     left = 40 - (realen(str) / 2) - 1;
  449.     right = 40 + (realen(str) / 2) + 1;
  450.     Save = BorderedMenu(left, R_TOP + 1, right, R_BTM + 1,
  451.         cfg.DepData.ScreenColors.StatFore,
  452.         cfg.DepData.ScreenColors.StatBack,
  453.         cfg.DepData.ScreenColors.StatFore,
  454.         cfg.DepData.ScreenColors.StatBack, title);
  455.     gotoxy(2, 2);
  456.     cprintf(str);
  457.     if (accept != NULL) {
  458.         do {
  459.             c = toupper(KeyStroke());
  460.         } while (strchr(accept, c) == NULL);
  461.     }
  462.     else KeyStroke();
  463.  
  464.     FreeBorderedMenu(left, R_TOP + 1, right, R_BTM + 1, Save);
  465.     return c;
  466. }
  467.  
  468. void Error(str)
  469. char *str;
  470. {
  471.     char work[100];
  472.  
  473.     ShowIt(" Error: ", str, NULL);
  474. }
  475.  
  476. char Confirm(char *str)
  477. {
  478.     char work[50];
  479.  
  480.     sprintf(work, "%s? (Y/N/C)", str);
  481.     return ShowIt(" System Addition ", work, "YCN");
  482. }
  483.  
  484. void RingBell() {}
  485.  
  486. void DoEdit()
  487. {
  488.     int ii, c, mode;
  489.     NetRec *temp;
  490.     void *Save;
  491.     SYS_FILE roomFile;
  492.  
  493.     if (cfg.netSize == 0) {
  494.         printf("No nets to play with!");
  495.         return;
  496.     }
  497.  
  498.     for (ii = 0; ii < cfg.netSize; ii++) {
  499.         getNet(ii, &netBuf);
  500.         if (netBuf.nbflags.in_use) {
  501.             temp = GetDynamic(sizeof *temp);
  502.             strCpy(temp->name, netBuf.netName);
  503.             strCpy(temp->id, netBuf.netId);
  504.             strCpy(temp->cond, netBuf.nbShort);
  505.             temp->num = ii;
  506.             AddData(&NetList.Data, temp, NULL, FALSE);
  507.         }
  508.     }
  509.  
  510.     makeSysName(roomFile, "ctdlroom.sys", &cfg.roomArea);
  511.     openFile(roomFile, &roomfl);
  512.     initRoomBuf(&roomBuf);
  513.  
  514.     NetList.bg = cfg.DepData.ScreenColors.ScrBack;
  515.     NetList.fg = cfg.DepData.ScreenColors.ScrFore;
  516.     NetList.dbg = cfg.DepData.ScreenColors.StatBack;
  517.     NetList.dfg = cfg.DepData.ScreenColors.StatFore;
  518.     temp = NULL;
  519.     mode = DEL_ACTIVE;
  520.     do {
  521.         if ((temp = DispList(&NetList, temp, &c, mode)) != NULL) {
  522.             Save = SaveImage(1, 1, 80, 25);
  523.             switch (c) {
  524.             case '\r':
  525.             case '\n':
  526.                 getNet(temp->num, &netBuf);
  527.                 RunEdit(TRUE);
  528.                 putNet(temp->num, &netBuf);
  529.                 mode |= NO_REFRESH;
  530.                 break;
  531.             case INS:
  532.                 ii = TRUE;
  533.                 killNetBuf(&netBuf);
  534.                 zero_struct(netBuf);
  535.                 initNetBuf(&netBuf);
  536.                 netBuf.nbRoute = -1;
  537.                 do {
  538.                     RunEdit(ii);
  539.                     ii = FALSE;
  540.                 } while (!ValNewSystem());
  541.                 mode &= ~(NO_REFRESH);
  542.                 break;
  543.             }
  544.             PutImage(1, 1, 80, 25, Save);
  545.         }
  546.     } while (temp != NULL);
  547.     clrscr();
  548.     printf(R_TITLE);
  549. }
  550.  
  551. int ValNewSystem()
  552. {
  553.     int i;
  554.     NetRec *temp;
  555.  
  556.     if (strLen(netBuf.netName) == 0) {
  557.         Error("Need Name field.");
  558.         return FALSE;
  559.     }
  560.  
  561.     if (strLen(netBuf.netId)   == 0) {
  562.         Error("Need Id field.");
  563.         return FALSE;
  564.     }
  565.  
  566.     switch (Confirm("Save")) {
  567.     case 'Y':
  568.         i = GetNewSlot(&netTemp);
  569.         netBuf.nbGen = netTemp.nbGen;
  570.         netBuf.nbflags.in_use = TRUE;
  571.         putNet(i, &netBuf);
  572.         InitVNode(i);
  573.         temp = GetDynamic(sizeof *temp);
  574.         strCpy(temp->name, netBuf.netName);
  575.         strCpy(temp->id, netBuf.netId);
  576.         temp->num = i;
  577.         AddData(&NetList.Data, temp, NULL, FALSE);
  578.         return TRUE;
  579.     case 'C': return FALSE;
  580.     case 'N': return TRUE;
  581.     }
  582. }
  583.  
  584. void DispNetName(NetRec *d)
  585. {
  586.     cprintf(d->name);
  587. }
  588.  
  589. int DoMN()
  590. {
  591.     char *save, Disabled = TRUE;
  592.     int  c, i;
  593.     MULTI_NET_DATA m = 1l;
  594.  
  595.     switch ((c = KeyStroke())) {
  596.     case ESC:
  597.     case UP:
  598.     case DOWN:
  599.     case LEFT:
  600.     case RIGHT:
  601.         return c;
  602.     case '\r':
  603.         return DOWN;
  604.     case '\b':
  605.         return UP;
  606.     }
  607.  
  608.     save = GetDynamic(2*(MN_RIGHT-MN_LEFT+1)*(MN_BOTTOM-MN_TOP+1));
  609.     gettext(MN_LEFT, MN_TOP, MN_RIGHT, MN_BOTTOM, save);
  610.  
  611.     ScreenIt(&MNets, TRUE);
  612.  
  613.     puttext(MN_LEFT, MN_TOP, MN_RIGHT, MN_BOTTOM, save);
  614.     free(save);
  615.  
  616.     for (i = 0; i < 32; i++, m <<= 1) {
  617.         if (mn[i]) Disabled = FALSE;
  618.     }
  619.  
  620.     strcpy(MNval, (Disabled) ? " Disabled " : " Active ");
  621.  
  622.     return 0;
  623. }
  624.  
  625. int DoRoomSharing()
  626. {
  627.     int  key, rover, count = 0, mode;
  628.     void *Save;
  629.     OneSharedRoom *data = NULL;
  630.     static DisplayList Rooms = { { NULL, NULL, NULL, free, NULL },
  631.             " Rooms Shared ",
  632.             NULL, NULL,
  633.             1, 80, 1, 25,
  634.             0, 0, 0, 0,
  635.             NAMESIZE + 4, DispRoomName, NULL, KeyStroke };
  636.  
  637.     Rooms.bg = cfg.DepData.ScreenColors.ScrBack;
  638.     Rooms.fg = cfg.DepData.ScreenColors.ScrFore;
  639.     Rooms.dbg = cfg.DepData.ScreenColors.StatBack;
  640.     Rooms.dfg = cfg.DepData.ScreenColors.StatFore;
  641.  
  642.     if ((key = KeyStroke()) != ' ') return key;
  643.  
  644.     KillList(&Rooms.Data);
  645.     for (rover = 0; rover < SHARED_ROOMS; rover++) {
  646.         if (isSharedRoom(thisNet, rover) &&
  647.                     roomValidate(thisNet, rover)) {
  648.             data = GetDynamic(sizeof *data);
  649.             strcpy(data->name, roomTab[netRoomSlot(rover)].rtname);
  650.             data->Room.ShareInfo = netBuf.netRooms[rover];
  651.             AddData(&Rooms.Data, data, NULL, FALSE);
  652.             count++;
  653.             data->mode = NORMAL_ROOM;
  654.         }
  655.     }
  656.  
  657.     VirtInit();
  658.     if (VirtualInUse) {
  659.         for (rover = 0; rover < VIRT_LIMIT; rover++) {
  660.             if (VirtNetList[thisNet].VirtList[rover].WhichVirt != -1) {
  661.                 key = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  662.                 data = GetDynamic(sizeof *data);
  663.                 data->mode = VIRTUAL_ROOM;
  664.                 data->Room.VirtRoom = VirtNetList[thisNet].VirtList[rover];
  665.                 strcpy(data->name, VRoomTab[key].vrName);
  666.                 AddData(&Rooms.Data, data, NULL, FALSE);
  667.                 count++;
  668.             }
  669.         }
  670.     }
  671.  
  672.     if (count == 0) {
  673.         Save = BorderedMenu(R_LEFT, R_TOP, R_RGT, R_BTM,
  674.             cfg.DepData.ScreenColors.StatFore,
  675.             cfg.DepData.ScreenColors.StatBack,
  676.             cfg.DepData.ScreenColors.StatFore,
  677.             cfg.DepData.ScreenColors.StatBack, "");
  678.  
  679.         gotoxy(2, 2);
  680.         cprintf("No rooms shared with %s.", netBuf.netName);
  681.         KeyStroke();
  682.         FreeBorderedMenu(R_LEFT, R_TOP, R_RGT, R_BTM, Save);
  683.         return 0;
  684.     }
  685.     Save = SaveImage(1, 1, 80, 25);
  686.     mode = 0;
  687.     data = NULL;
  688.     while ((data = DispList(&Rooms, data, &key, mode)) != NULL) {
  689.         RoomInfo(data);
  690.         mode |= NO_REFRESH;
  691.     }
  692.     PutImage(1, 1, 80, 25, Save);
  693.     return 0;     /* important */
  694. }
  695.  
  696. void DispRoomName(OneSharedRoom *d)
  697. {
  698.     cprintf("%s", d->name);
  699. }
  700.  
  701. #define BTM     12
  702. #define TOP     8
  703. #define RGT     64
  704. #define W_LEFT  16
  705. char KillNode(NetRec *which)
  706. {
  707.     void *Save;
  708.     int  c;
  709.     char toReturn;
  710.  
  711.     Save = BorderedMenu(W_LEFT, TOP, RGT, BTM,
  712.         cfg.DepData.ScreenColors.StatFore,
  713.         cfg.DepData.ScreenColors.StatBack,
  714.         cfg.DepData.ScreenColors.StatFore,
  715.         cfg.DepData.ScreenColors.StatBack, "");
  716.  
  717.     gotoxy(2, 2);
  718.     cprintf("Really kill %s? ", which->name);
  719.     do
  720.         c = toupper(KeyStroke());
  721.     while (c != ESC && c != 'Y' && c != 'N');
  722.  
  723.     if (c == 'Y') {
  724.         getNet(which->num, &netBuf);
  725.         if (netBuf.nbflags.HasRouted) {
  726.             clrscr();
  727.             gotoxy(3, 2);
  728.             cprintf(ROUTE_WARNING);
  729.             gotoxy(3, 3);
  730.             cprintf(ROUTE_CONFIRM, netBuf.netName);
  731.             do
  732.                 c = toupper(KeyStroke());
  733.             while (c != ESC && c != 'Y' && c != 'N');
  734.             if (c == 'Y')
  735.                 toReturn = TRUE;
  736.             else toReturn = FALSE;
  737.         }
  738.         else toReturn = TRUE;
  739.  
  740.         if (toReturn) {
  741.             KillAuxFiles();
  742.             netBuf.nbflags.in_use = FALSE;
  743.             putNet(which->num, &netBuf);
  744.             toReturn = TRUE;
  745.         }
  746.     }
  747.     else toReturn = FALSE;
  748.  
  749.     FreeBorderedMenu(W_LEFT, TOP, RGT, BTM, Save);
  750.  
  751.     return toReturn;
  752. }
  753.  
  754. void KillAuxFiles()
  755. {
  756.     SYS_FILE fn, fn2;
  757.     label    temp, Id, OurId;
  758.     int      i, j;
  759.     extern FILE *upfd;
  760.     extern NetBuffer nBuf1;
  761.  
  762.     sPrintf(temp, "%d.ml", thisNet);
  763.     makeSysName(fn, temp, &cfg.netArea);
  764.     unlink(fn);
  765.  
  766.     sPrintf(temp, "%d.rfl", thisNet);
  767.     makeSysName(fn, temp, &cfg.netArea);
  768.     unlink(fn);
  769.  
  770.     sPrintf(temp, "%d.sfl", thisNet);
  771.     makeSysName(fn, temp, &cfg.netArea);
  772.     unlink(fn);
  773.  
  774.     sPrintf(temp, "%d.vtx", thisNet);
  775.     makeSysName(fn, temp, &cfg.netArea);
  776.     unlink(fn);
  777.  
  778.     for (i = 0; ; i++) {
  779.         sPrintf(temp, "R%d.%d", thisNet, i);
  780.         makeSysName(fn, temp, &cfg.netArea);
  781.         if (unlink(fn) != 0) break;
  782.     }
  783.  
  784.     if (!DirectRoute(&netBuf)) {
  785.         normId(netBuf.netId, OurId);
  786.         getNet(netBuf.nbRoute, &nBuf1);
  787.         for (i = 0; ; ) {
  788.             sPrintf(temp, "R%d.%d", netBuf.nbRoute, i);
  789.             makeSysName(fn, temp, &cfg.netArea);
  790.             if ((upfd = fopen(fn, READ_ANY)) == NULL)
  791.                 break;
  792.             getMsgStr(getNetChar, Id, NAMESIZE);
  793.             fclose(upfd);
  794.             NormStr(Id);
  795.             if (strCmpU(OurId, Id) == SAMESTRING) {
  796.                 unlink(fn);
  797.                 for (j = i + 1; ; j++) {
  798.                     sPrintf(temp, "R%d.%d", netBuf.nbRoute,
  799.                         j);
  800.                     makeSysName(fn, temp, &cfg.netArea);
  801.                     if (access(fn, 0) != 0) break;
  802.                     sPrintf(temp, "R%d.%d", netBuf.nbRoute,
  803.                         j - 1);
  804.                     makeSysName(fn2, temp, &cfg.netArea);
  805.                     rename(fn, fn2);
  806.                 }
  807.             }
  808.             else i++;
  809.         }
  810.         if (i == 0)
  811.             nBuf1.nbflags.HasRouted = FALSE;
  812.         netBuf.nbHiRouteInd = i - 1;
  813.         putNet(netBuf.nbRoute, &nBuf1);
  814.     }
  815. }
  816.  
  817. void ReDoAuxFiles(NewId)
  818. label NewId;
  819. {
  820.     label ThisId;
  821.     int AuxWork(int target, label ThisId, label NewId);
  822.  
  823.     normId(netBuf.netId, ThisId);
  824.     AuxWork(netBuf.nbRoute, ThisId, NewId);
  825.     AuxWork(thisNet, ThisId, NewId);
  826. }
  827.  
  828. AuxWork(target, ThisId, NewId)
  829. int target;
  830. label ThisId, NewId;
  831. {
  832.     label temp, Name, Id;
  833.     SYS_FILE fn;
  834.     int     rover = 0;
  835.     FILE *fd;
  836.     extern char *R_W_ANY;
  837.  
  838.     if (strCmpU(NewId, ThisId) != SAMESTRING) {
  839.     do {
  840.         sPrintf(temp, "R%d.%d", target, rover++);
  841.         makeSysName(fn, temp, &cfg.netArea);
  842.         if (IdRouteFile(fn, Id, Name)) {
  843.         if (strCmpU(Id, ThisId) == SAMESTRING) {
  844.             fd = fopen(fn, R_W_ANY);
  845.             fprintf(fd, "%-20s", NewId);
  846.             fclose(fd);
  847.         }
  848.         }
  849.         else break;
  850.     } while (TRUE);
  851.     }
  852. }
  853.  
  854. char *LastOn(long s, char d);
  855.  
  856. void NodeInfo()
  857. {
  858.     SetColors(cfg.DepData.ScreenColors.StatFore, cfg.DepData.ScreenColors.StatBack);
  859.     gotoxy(2, 25);
  860.     cprintf("Last contacted: %s", LastOn(netBuf.nbLastConnect, FALSE));
  861. }
  862.  
  863. #define MSG        "Don't forget to set the Access field."
  864. #define ERR_TOP        9
  865. #define ERR_BOTTOM    (ERR_TOP + 4)
  866. #define ERR_RIGHT    (42 + (strlen(MSG) / 2))
  867. #define ERR_LEFT    (35 - (strlen(MSG) / 2))
  868. char ExtWarn(char *newval)
  869. {
  870.     char *Save;
  871.  
  872.     if (*newval) {
  873.         Save = BorderedMenu(ERR_LEFT, ERR_TOP, ERR_RIGHT, ERR_BOTTOM,
  874.                     WHITE, RED, WHITE, RED, "");
  875.         gotoxy(3, 2);
  876.         cprintf(MSG);
  877.         KeyStroke();
  878.         FreeBorderedMenu(ERR_LEFT,ERR_TOP, ERR_RIGHT, ERR_BOTTOM, Save);
  879.     }
  880.     else {
  881.         netBuf.access[0] = 0;
  882.         SuddenUpdate(&Node, AccessElement);
  883.     }
  884.     return TRUE;
  885. }
  886.  
  887. #define ROOM_BTM        14
  888. #define ROOM_TOP        8
  889. #define ROOM_RGT        64
  890. #define ROOM_LEFT        16
  891. void RoomInfo(OneSharedRoom *data)
  892. {
  893.     void *Save;
  894.     char moo[20];
  895.     int roomno;
  896.  
  897.     Save = BorderedMenu(ROOM_LEFT, ROOM_TOP, ROOM_RGT, ROOM_BTM,
  898.             cfg.DepData.ScreenColors.StatFore,
  899.             cfg.DepData.ScreenColors.StatBack,
  900.             cfg.DepData.ScreenColors.StatFore,
  901.             cfg.DepData.ScreenColors.StatBack, "");
  902.  
  903.     if (data->mode == NORMAL_ROOM) {
  904.         if ((roomno = roomExists(data->name)) == ERROR) {
  905.             gotoxy(2, 2);
  906.             cprintf("Ooops, internal bug.");
  907.         }
  908.         else {
  909.             getRoom(roomno);
  910.             gotoxy(2, 1);
  911.             cprintf("%s", data->name);
  912.             gotoxy(2, 3);
  913.             if (roomBuf.rbShareType == PEON)
  914.                 cprintf("Peon relationship");
  915.             else switch (data->Room.ShareInfo.mode) {
  916.             case PEON:
  917.                 cprintf("Peon relationship");
  918.                 break;
  919.             case PASS_BACKBONE:
  920.                 cprintf("Passive Backbone relationship");
  921.                 break;
  922.             case ACTIVE_BACKBONE:
  923.                 cprintf("Active Backbone relationship");
  924.                 break;
  925.             default:
  926.                 cprintf("OOPS: %d", data->Room.ShareInfo.mode);
  927.             }
  928.             gotoxy(2, 4);
  929.             cprintf("Last message sent was %s.",
  930.                     PrintPretty(data->Room.ShareInfo.lastMess, moo));
  931.         }
  932.     }
  933.     else {
  934.         gotoxy(2, 1);
  935.         cprintf("%s", data->name);
  936.         gotoxy(2, 3);
  937.         switch (data->Room.VirtRoom.mode) {
  938.         case PEON:
  939.             cprintf("Peon relationship");
  940.             break;
  941.         case PASS_BACKBONE:
  942.             cprintf("Passive Backbone relationship");
  943.             break;
  944.         case ACTIVE_BACKBONE:
  945.             cprintf("Active Backbone relationship");
  946.             break;
  947.         default:
  948.             cprintf("OOPS: %d", data->Room.ShareInfo.mode);
  949.         }
  950.         gotoxy(2, 4);
  951.         cprintf("A virtual room.");
  952.     }
  953.     KeyStroke();
  954.     FreeBorderedMenu(ROOM_LEFT, ROOM_TOP, ROOM_RGT, ROOM_BTM, Save);
  955. }
  956.  
  957. /************************************************************************/
  958. /*    roomExists() returns slot# of named room else ERROR             */
  959. /************************************************************************/
  960. int roomExists(char *room)
  961. {
  962.     int i;
  963.  
  964.     for (i = 0;  i < MAXROOMS;  i++) {
  965.         if (
  966.             roomTab[i].rtflags.INUSE == 1   &&
  967.             strCmpU(room, roomTab[i].rtname) == SAMESTRING
  968.         ) {
  969.             return(i);
  970.         }
  971.     }
  972.     return(ERROR);
  973. }
  974.